#include "qtuiolistener.h"
#include "TUIO/TuioListener.h"
#include "TUIO/TuioObject.h"
#include "TUIO/TuioCursor.h"
#include "TUIO/TuioTime.h"
#include <QPoint>
#include <QApplication>
#include <QWidget>
#include <QMainWindow>
#include "stdio.h"
#include <QCoreApplication> 
#include <QTouchEvent>

QTuioListener::QTuioListener()
{
}

void QTuioListener::addTuioObject(TuioObject *tobj){

}

void QTuioListener::updateTuioObject(TuioObject *tobj){

}

void QTuioListener::removeTuioObject(TuioObject *tobj){

}

void QTuioListener::addTuioCursor(TuioCursor *tcur){
    QPointF pos = QPointF(tcur->getX(), tcur->getY());
    QTouch touch = QTouch(tcur->getCursorID(), pos);
    QTouchEvent event = QTouchEvent(TouchType(TOUCHDOWN), touch); 
    QCoreApplication::sendEvent(this.eventHandler, event);

    // descobre qual o widget sob o ponto
    // cria um TouchPoint (mas e coordenadas?)
    // envia o evento pra o widget q eh o main window, e espera q ele repasse aos filhos
    //  traduzir tamanho aqui ou depois???

}

void QTuioListener::updateTuioCursor(TuioCursor *tcur){
    QPointF pos = QPointF(tcur->getX(), tcur->getY());
    QTouch touch = QTouch(tcur->getCursorID(), pos);
    QTouchEvent event = QTouchEvent(TouchType(TOUCHMOVE), touch); 
    QCoreApplication::sendEvent(this.eventHandler, event);


}

void QTuioListener::removeTuioCursor(TuioCursor *tcur){
    QPointF pos = QPointF(tcur->getX(), tcur->getY());
    QTouch touch = QTouch(tcur->getCursorID(), pos);
    QTouchEvent event = QTouchEvent(TouchType(TOUCHUP), touch); 
    QCoreApplication::sendEvent(this.eventHandler, event);


}

void QTuioListener::refresh(TuioTime frameTime) {
    return;
}

void QTuioListener::setEventHandler(QObject *obj) {
    this.eventHandler = obj;
}
